
cd "/Users/chuangchen/Library/CloudStorage/OneDrive-UniversityofPittsburgh/Pela project"

use "/Users/chuangchen/Library/CloudStorage/OneDrive-UniversityofPittsburgh/LASA/Datos/all_countries3.dta", clear

* recode the same-sex marriage question
* moral conservative
gen pro_ssm= 0 if val_ssm <=3
* moral middle
replace pro_ssm=1 if val_ssm <=7 & val_ssm>3
* moral progressive
replace pro_ssm=2 if val_ssm >7
replace pro_ssm=. if val_ssm >10
lab value pro_ssm pro_abort_lab

gen eco_moral4 = 1 if pro_ssm == 0 & pro_regulation2==0
replace eco_moral4 = 2 if pro_ssm == 0 & pro_regulation2==1
replace eco_moral4 = 3 if pro_ssm == 0 & pro_regulation2==2
replace eco_moral4 = 4 if pro_ssm == 1 & pro_regulation2==0
replace eco_moral4 = 5 if pro_ssm == 1 & pro_regulation2==1
replace eco_moral4 = 6 if pro_ssm == 1 & pro_regulation2==2
replace eco_moral4 = 7 if pro_ssm == 2 & pro_regulation2==0
replace eco_moral4 = 8 if pro_ssm == 2 & pro_regulation2==1
replace eco_moral4 = 9 if pro_ssm == 2 & pro_regulation2==2
lab value eco_moral4 eco_moral2_lab




gen eco_moral_recode=.

replace eco_moral_recode=eco_moral2
lab value eco_moral_recode eco_moral2_lab


*****************************************
* robustness check
* using ID2
est clear

*Model 3
eststo: mlogit party_family2 ib5.eco_moral_recode i.age_party_recode age N_party_member female education religious i.wave i.pais_n, vce(cluster partido) base(2)

*estout using "model3_coef.csv", cells(b ci_l ci_u) replace
margins, at(eco_moral_recode=(1(1)9)) predict(outcome(1)) saving("model3_tmp1.dta")
margins, at(eco_moral_recode=(1(1)9)) predict(outcome(2)) saving("model3_tmp2.dta")
margins, at(eco_moral_recode=(1(1)9)) predict(outcome(3)) saving("model3_tmp3.dta")

replace eco_moral_recode=eco_moral4
*Model 4
eststo: mlogit party_family2 ib5.eco_moral_recode i.age_party_recode age N_party_member female education religious i.wave i.pais_n, vce(cluster partido) base(2)

*estout using "model4_coef.csv", cells(b ci_l ci_u) replace
margins, at(eco_moral_recode=(1(1)9)) predict(outcome(1)) saving("model4_tmp1.dta")
margins, at(eco_moral_recode=(1(1)9)) predict(outcome(2)) saving("model4_tmp2.dta")
margins, at(eco_moral_recode=(1(1)9)) predict(outcome(3)) saving("model4_tmp3.dta")

esttab using "regression_IV_ID2.tex", drop(_cons *wave *pais_n) wide pr2 aic aux(se) scalars("ll Log lik.") star(+ 0.10 * 0.05 ** 0.01 *** 0.001) b(3) label varwidth(33) interaction("$\times$") mtitles("Multinomial Logistic Regression (DV: ID2)") nobaselevels unstack nodepvars noomitted replace 




* replace economic regulation with pension

replace eco_pensions = round(eco_pensions)

gen pension_recode = .
* 0 means private companies should be responsible for pension (conservative)
replace pension_recode = 0 if eco_pensions == 1 | eco_pensions == 2
replace pension_recode = 1 if eco_pensions == 3 | eco_pensions == 4 | eco_pensions == 5
* 2 means the state should be responsible for pension (progressive)
replace pension_recode = 2 if eco_pensions == 6 | eco_pensions == 7
lab define pension_lab 0 "Eco Conservative" 1 "Eco Middle" 2 "Eco Progressive"
lab value pension_recode pension_lab

gen eco_moral3 = 1 if pro_abortion2 == 0 & pension_recode==0
replace eco_moral3 = 2 if pro_abortion2 == 0 & pension_recode==1
replace eco_moral3 = 3 if pro_abortion2 == 0 & pension_recode==2
replace eco_moral3 = 4 if pro_abortion2 == 1 & pension_recode==0
replace eco_moral3 = 5 if pro_abortion2 == 1 & pension_recode==1
replace eco_moral3 = 6 if pro_abortion2 == 1 & pension_recode==2
replace eco_moral3 = 7 if pro_abortion2 == 2 & pension_recode==0
replace eco_moral3 = 8 if pro_abortion2 == 2 & pension_recode==1
replace eco_moral3 = 9 if pro_abortion2 == 2 & pension_recode==2
lab value eco_moral3 eco_moral2_lab

est clear
replace eco_moral_recode=eco_moral3

* Model 5, abortion + pension
eststo: mlogit party_family ib5.eco_moral_recode i.age_party_recode age N_party_member female education religious i.wave i.pais_n, vce(cluster partido) base(2)

*estout using "model5_coef.csv", cells(b ci_l ci_u) replace
margins, at(eco_moral_recode=(1(1)9)) predict(outcome(1)) saving("model5_tmp1.dta")
margins, at(eco_moral_recode=(1(1)9)) predict(outcome(2)) saving("model5_tmp2.dta")
margins, at(eco_moral_recode=(1(1)9)) predict(outcome(3)) saving("model5_tmp3.dta")

*esttab using "regression_ID1_robust_pension.tex", drop(_cons *wave *pais_n) wide pr2 aic aux(se) scalars("ll Log lik.") star(+ 0.10 * 0.05 ** 0.01 *** 0.001) b(3) label varwidth(33) interaction("$\times$") mtitles("Multinomial Logistic Regression (DV: ID1)") nobaselevels unstack nodepvars noomitted replace 



*est clear

gen eco_moral5 = 1 if pro_ssm == 0 & pension_recode==0
replace eco_moral5 = 2 if pro_ssm == 0 & pension_recode==1
replace eco_moral5 = 3 if pro_ssm == 0 & pension_recode==2
replace eco_moral5 = 4 if pro_ssm == 1 & pension_recode==0
replace eco_moral5 = 5 if pro_ssm == 1 & pension_recode==1
replace eco_moral5 = 6 if pro_ssm == 1 & pension_recode==2
replace eco_moral5 = 7 if pro_ssm == 2 & pension_recode==0
replace eco_moral5 = 8 if pro_ssm == 2 & pension_recode==1
replace eco_moral5 = 9 if pro_ssm == 2 & pension_recode==2
lab value eco_moral5 eco_moral2_lab

replace eco_moral_recode=eco_moral5

* Model 6, ssm + pension
eststo: mlogit party_family ib5.eco_moral_recode i.age_party_recode age N_party_member female education religious i.wave i.pais_n, vce(cluster partido) base(2)

*estout using "model6_coef.csv", cells(b ci_l ci_u) replace
margins, at(eco_moral_recode=(1(1)9)) predict(outcome(1)) saving("model6_tmp1.dta")
margins, at(eco_moral_recode=(1(1)9)) predict(outcome(2)) saving("model6_tmp2.dta")
margins, at(eco_moral_recode=(1(1)9)) predict(outcome(3)) saving("model6_tmp3.dta")

esttab using "regression_IV_ID1_robust_ssm_pensions.tex", drop(_cons *wave *pais_n) wide pr2 aic aux(se) scalars("ll Log lik.") star(+ 0.10 * 0.05 ** 0.01 *** 0.001) b(3) label varwidth(33) interaction("$\times$") mtitles("Multinomial Logistic Regression (DV: ID1)") nobaselevels unstack nodepvars noomitted replace 



est clear

* now change DV to continuous
* Model 7
eststo: reg ID1 ib5.eco_moral2 i.age_party_recode age N_party_member female education religious i.wave i.pais_n, vce(cluster partido)

margins eco_moral2
marginsplot, recast(scatter) title("") xlabel(, labsize(small)) xtitle("Policy Mix", size(normal)) ytitle("Predicted Ideology", size(nomral)) graphregion(color(white)) plotregion(margin(small)) ysize(2) xsize(2.7) scale(1)
graph export "model7.png", replace

esttab using "regression_IV_ID1_robust_continuous1.tex", drop(_cons *wave *pais_n) wide r2 aic aux(se) scalars("ll Log lik.") star(+ 0.10 * 0.05 ** 0.01 *** 0.001) b(3) label varwidth(33) interaction("$\times$") mtitles("") nobaselevels unstack nodepvars noomitted replace 




* now try quantiles
xtile eco_pct = eco_regulated, nq(3)
lab define eco_pct_lab 1 "Eco Progressive" 2 "Eco Middle" 3 "Eco Conservative"
lab value eco_pct eco_pct_lab
tab eco_regulated eco_pct

xtile moral_pct = val_abortion, nq(3)
lab define moral_pct_lab 3 "Moral Progressive" 2 "Moral Middle" 1 "Moral Conservative"
lab value moral_pct moral_pct_lab
tab val_abortion moral_pct

gen eco_moral2_quan = 1 if eco_pct == 3 & moral_pct == 1
replace eco_moral2_quan = 2 if eco_pct == 3 & moral_pct == 2
replace eco_moral2_quan = 3 if eco_pct == 3 & moral_pct == 3
replace eco_moral2_quan = 4 if eco_pct == 2 & moral_pct == 1
replace eco_moral2_quan = 5 if eco_pct == 2 & moral_pct == 2
replace eco_moral2_quan = 6 if eco_pct == 2 & moral_pct == 3
replace eco_moral2_quan = 7 if eco_pct == 1 & moral_pct == 1
replace eco_moral2_quan = 8 if eco_pct == 1 & moral_pct == 2
replace eco_moral2_quan = 9 if eco_pct == 1 & moral_pct == 3
lab define eco_moral2_quan_lab 1 "McEc" 2 "McEm" 3 "McEp" 4 "MmEc" 5 "MmEm" 6 "MmEp" 7 "MpEc" 8 "MpEm" 9 "MpEp"
lab value eco_moral2_quan eco_moral2_quan_lab

xtile party_family_quan = ID1, nq(3)
lab value party_family_quan party_family_lab
tab ID1 party_family_quan

est clear

* Model 8, IV is based quantiles
eststo: mlogit party_family ib5.eco_moral2_quan i.age_party_recode age N_party_member female education religious i.wave i.pais_n, vce(cluster partido) base(2)

margins, at(eco_moral2_quan=(1(1)9)) predict(outcome(1)) saving("model8_tmp1.dta")
margins, at(eco_moral2_quan=(1(1)9)) predict(outcome(2)) saving("model8_tmp2.dta")
margins, at(eco_moral2_quan=(1(1)9)) predict(outcome(3)) saving("model8_tmp3.dta")

* Model 9, both IV and DV are based on quantiles
eststo: mlogit party_family_quan ib5.eco_moral2_quan i.age_party_recode age N_party_member female education religious i.wave i.pais_n, vce(cluster partido) base(2)

margins, at(eco_moral2_quan=(1(1)9)) predict(outcome(1)) saving("model9_tmp1.dta")
margins, at(eco_moral2_quan=(1(1)9)) predict(outcome(2)) saving("model9_tmp2.dta")
margins, at(eco_moral2_quan=(1(1)9)) predict(outcome(3)) saving("model9_tmp3.dta")

esttab using "regression_9cat_IV_ID1_quan.tex", drop(_cons *wave *pais_n) wide pr2 aic aux(se) scalars("ll Log lik.") star(+ 0.10 * 0.05 ** 0.01 *** 0.001) b(3) label varwidth(33) interaction("$\times$") mtitles("Multinomial Logistic Regression (DV: ID1)") nobaselevels unstack nodepvars noomitted replace 



